home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  699 b   |  32 lines

  1. #define CONST
  2. #define SIZET int
  3. /*
  4.  * strstr - find first occurrence of wanted in s
  5.  */
  6.  
  7. #define    NULL    0
  8.  
  9. char *                /* found string, or NULL if none */
  10. strstr(s, wanted)
  11. CONST char *s;
  12. CONST char *wanted;
  13. {
  14.     register CONST char *scan;
  15.     register SIZET len;
  16.     register char firstc;
  17.     extern int strcmp();
  18.     extern SIZET strlen();
  19.  
  20.     /*
  21.      * The odd placement of the two tests is so "" is findable.
  22.      * Also, we inline the first char for speed.
  23.      * The ++ on scan has been moved down for optimization.
  24.      */
  25.     firstc = *wanted;
  26.     len = strlen(wanted);
  27.     for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
  28.         if (*scan++ == '\0')
  29.             return(NULL);
  30.     return(scan);
  31. }
  32.